<!DOCTYPE html>
<html xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <title>layui后台管理模板</title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="format-detection" content="telephone=no"/>
    <link rel="stylesheet" href="/webjars/layui/2.3.0/css/layui.css" media="all"/>
    <script type="text/javascript" src="/webjars/layui/2.3.0/layui.js"></script>
    <script type="text/javascript" src="/asset/js/lp.js"></script>
    <script type="text/javascript" src="/asset/js/jquery-3.2.1.min.js"></script>
    <script src="/webjars/vue/2.5.3-1/vue.min.js"></script>
</head>
<body class="childrenBody">
<form class="layui-form" style="width:70%;margin-left: 10%" action="/governor/user/addUser" method="post">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名称</label>
        <div class="layui-input-block">
            <div style="float: left;width:50%;">
                <input type="text" name="name" class="layui-input userName" lay-verify="required"
                       placeholder="请输入用户名称"/>
            </div>
        </div>
    </div>
    <div id="appKey" class="layui-form-item">
        <label class="layui-form-label">appKey</label>
        <div class="layui-input-block">
            <div style="float: left;width:50%;">
                <input type="text" v-model="appkey" name="appKey" class="layui-input userName" lay-verify="required"
                       v-bind="appkey" placeholder="请输入或生成appkey"/>
            </div>
            <div style="float: left">
                <input type="button" class="layui-btn" v-on:click="getAppkey" value="生成"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="lay-submit" lay-filter="addUser">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(['form'], function () {
        var form = layui.form;
        //监听提交
        form.on('submit(addUser)', function (data) {
            //监听提交
                $.post({
                    url:data.form.action,
                    data:{
                        json:JSON.stringify(data.field)
                    },
                    success:function (json) {
                        var status = json.status;
                        if(status==200){
                            layer.msg("添加成功");
                            form.reset();
                        }else{
                            layer.msg(json.msg);
                        }
                    },
                    error: function(data) {
                        layer.msg("网络错误");
                    }
                });
                return false;
        });
    });

    var App = new Vue({
        el: '#appKey',
        data: {
            appkey: ""
        },
        methods: {
            getAppkey: function () {
                var url = "/util/uid";
                var _self = this;
                $.get(url, function (data) {
                    console.log(data)
                    _self.appkey = data.result;
                })
            }
        }
    });
</script>
</body>
</html>